

//引入vue
import Vue from 'vue'
//引入app组件
import App from './App.vue'
//引入axios
import Axios from 'axios'
//引入element-ui
import Element from 'element-ui'
//引入element-ui全局样式
// import 'element-ui/lib/theme-chalk/index.css'
// 浅绿色主题
import './assets/css/theme-green/index.css';
//引入路由配置
import {router} from "./router";
//引入store
import {store} from "./store/store";
import MultiFileUpload from './components/common/upload/MultiFileUpload.vue'
//引入babel-polyfill
import 'babel-polyfill'

//安装element-ui插件
Vue.use(Element)
Vue.component('MultiFileUpload',MultiFileUpload)

Vue.config.productionTip = false
//绑定axios
Vue.prototype.$axios = Axios
//配置axios全局配置
Axios.defaults.baseURL = 'http://localhost/'
//绑定message
Vue.prototype.$message = Element.Message
Vue.prototype.$loadingPage = Element.Loading

new Vue({
    render: h => h(App),
    router,
    store,
    created() {
        //在页面加载时读取sessionStorage里的状态信息
        if (sessionStorage.getItem("store")) {
            //重置state
            this.$store.replaceState(Object.assign({}, this.$store.state, JSON.parse(sessionStorage.getItem("store"))))
            //解决页面刷新不会再携带token问题
            this.$axios.defaults.headers = {
                'token':this.$store.state.token
            }
        }

        //在页面刷新时将vuex里的信息保存到sessionStorage里
        window.addEventListener("beforeunload", () => {
            sessionStorage.setItem("store", JSON.stringify(this.$store.state))
        })
    }
}).$mount('#app')
